package com.fenghongzhang.a1810;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

/**
 * 自定义对话框
 */
public class MyDialog extends Dialog {
    private TextView ti;
    private TextView message;
    private Button no;
    private static final String TAG = "MyDialog";
    private Button yes;
    public MyDialog(@NonNull Context context) {
        super(context);
    }

    private String strTi;

    public void setStrTi(String strTi) {
        this.strTi = strTi;
    }

    //2 成员
    private String strMsg;

    //3,设置set方法
    public void setStrMsg(String strMsg) {
        this.strMsg = strMsg;
    }

    public interface YesOnClick{
        void click();
    }

    private YesOnClick yesOnClick;

    public void setYesOnClick(YesOnClick yesOnClick) {
        this.yesOnClick = yesOnClick;
    }

    //1,声明接口
    public interface NoOnClick{
        void click();
    }

    //2声明成员变量
    private NoOnClick noOnClick;

    //3,设置->给接口赋值
    public void setNoOnClick(NoOnClick noOnClick) {
        this.noOnClick = noOnClick;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_layout);

        //1,find
        ti = (TextView) findViewById(R.id.title);
        message = (TextView) findViewById(R.id.message);
        no = (Button) findViewById(R.id.no);
        yes = (Button) findViewById(R.id.yes);

        //4,绑定
        message.setText(strMsg);

        ti.setText(strTi);

        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Log.i(TAG, "onClick: ");
                dismiss();
                yesOnClick.click();
            }
        });

        //点击事件
         no.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Log.i(TAG, "onClick: ");
                 dismiss();
                 noOnClick.click();
             }
         });
    }
}
